package com.lexed.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.lexed.pojo.Emp;
import com.lexed.service.EmpService;

/**
 * Servlet implementation class Register
 */
public class Register extends HttpServlet {
	
	private EmpService empService = new EmpService();
	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		String respassword = request.getParameter("respassword");
		
		if(password.equals(respassword)){
			
			Emp emp = new Emp();
			emp.setUname(username);
			emp.setPwd(password);
			emp.setDept("sale");
			
			try {
				empService.insert(emp);
				response.sendRedirect("login.html");
			} catch (Exception e) {
				response.sendRedirect("index.html");
				e.printStackTrace();
			}
		}else{
			response.sendRedirect("reg.html");
		}
		
	}

}
